/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import type { UserVo } from "~/base/api/user.ts";
import { page } from "~/school/api/school";
export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: UserVo
): MaFormItem[] {
  if (formType === "add") {
    // model.password = "123456";
  }

  const treeSelectRef = ref();
  const schools = ref<any[]>([]);
  page({
    //@ts-ignore
    page_size: 100,
  }).then((res) => {
    schools.value = res.data.list;
  });
  return [
    {
      label: () => t("departments.school_id"),
      prop: "school_id",
      render: () => (
        <el-tree-select
          ref={treeSelectRef}
          data={schools.value}
          props={{ value: 'id', label: 'name' }}
          check-strictly={true}
          default-expand-all={true}
          clearable={true}
        >
          {{
            default: ({ node }) => {
              const { meta } = node.data;
              node.data.title = meta?.i18n
                ? useTrans(meta.i18n)
                : meta?.title ?? "unknown";
            },
          }}
        </el-tree-select>
      ),
      renderProps: {
        class: "w-full",
        placeholder: t("form.pleaseSelect", {
          msg: t("departments.school_id"),
        }),
      },
      cols: { lg: 12, md: 24 },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredSelect", {
              msg: t("departments.school_id"),
            }),
          },
        ],
      },
    },
    {
      label: () => t("departments.name"),
      prop: "name",
      render: "input",
      cols: { md: 12, xs: 24 },
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: t("departments.name") }),
      },
      itemProps: {
        rules: [
          {
            required: true,
            message: t("form.requiredInput", { msg: t("departments.name") }),
          },
        ],
      },
    },
  ];
}
